﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BTGISWASECO.BusinessEntities;
using System.Data;

/// <summary>
/// Summary description for DongHoKhachHangDAL
/// </summary>
/// 
namespace BTGISWASECO.DataLayer
{
    public class DongHoKhachHangDAL
    {
        static System.Data.DataTable resultsDataTable;
        static ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer rs;
        public DongHoKhachHangDAL(ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer resultsGraphicsLayer)
        {
            resultsDataTable = resultsGraphicsLayer;
        }

        public DongHoKhachHangDAL()
        {

        }
        public DongHoKhachHangEntities GetDongHoKhachHangEntitiesByID(int id)
        {
            DongHoKhachHangEntities DongHoKhachHang = new DongHoKhachHangEntities();

            List<DongHoKhachHangEntities> list = GetList();
            foreach (DongHoKhachHangEntities b in list)
                if (b.OBJECTID == id)
                {
                    DongHoKhachHang = b;
                    break;
                }

            return DongHoKhachHang;
        }

        public DongHoKhachHangEntities GetDongHoKhachHangEntitiesByID()
        {
            DongHoKhachHangEntities DongHoKhachHang = new DongHoKhachHangEntities();

            List<DongHoKhachHangEntities> list = GetList();
            foreach (DongHoKhachHangEntities b in list)
                {
                    DongHoKhachHang = b;
                    break;
                }

            return DongHoKhachHang;
        }

        public static List<DongHoKhachHangEntities> GetList()
        {
            
            DataAccessHelper db = new DataAccessHelper();
            DataTable dt = db.GetDateTable();

            List<DongHoKhachHangEntities> list = new List<DongHoKhachHangEntities>();

            foreach (DataRow row in dt.Rows)
            {
                list.Add(new DongHoKhachHangEntities(row));
            }

            return list;
        }


        public static List<DongHoKhachHangEntities> GetListByName(string keyword)
        {
            DataAccessHelper db = new DataAccessHelper();
            DataTable dt = resultsDataTable;

            List<DongHoKhachHangEntities> list = new List<DongHoKhachHangEntities>();

            foreach (DataRow row in dt.Rows)
            {
                list.Add(new DongHoKhachHangEntities(row));
            }
            return list;
        }

        //public bool Insert(DongHoKhachHangEntities DongHoKhachHang)
        //{
        //   // int count = db.ExecuteNonQuery("INSERT INTO DongHoKhachHangEntitiess VALUES(N'" + DongHoKhachHang.DongHoKhachHangEntitiesName + "',N'" + DongHoKhachHang.Author + "'," + DongHoKhachHang.Amount + "," + DongHoKhachHang.Price + ")");
        //   // return count > 0;
        //    re
        //}

        //public bool Update(DongHoKhachHangEntities DongHoKhachHang)
        //{
        //    int count = db.ExecuteNonQuery("UPDATE DongHoKhachHangEntitiess SET DongHoKhachHangEntitiesName = N'" + DongHoKhachHang.DongHoKhachHangEntitiesName + "',Author = N'" + DongHoKhachHang.Author + "',Amount=" + DongHoKhachHang.Amount + ",Price=" + DongHoKhachHang.Price + " WHERE DongHoKhachHangEntitiesID = " + DongHoKhachHang.DongHoKhachHangEntitiesID);
        //    return count > 0;
        //}

        //public bool Delete(DongHoKhachHangEntities DongHoKhachHang)
        //{
        //    int count = db.ExecuteNonQuery("DELETE DongHoKhachHangEntitiess WHERE DongHoKhachHangEntitiesID=" + DongHoKhachHang.DongHoKhachHangEntitiesID);
        //    return count > 0;
        //}

        public static DataTable GetDateTable(ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer resultsGraphicsLayer)
        {
            System.Data.DataTable resultsDataTable = resultsGraphicsLayer;
            return resultsDataTable;
        }
    }
}